<?php
require_once ZEAI.'cache/config_pay.php';
$ifalipay    = (empty($_PAY['alipay_appid']))?false:true;
$ifweixinpay = (empty($_PAY['wxpay_mchid']))?false:true;
$ifrmb = ($cook_money >= $money && $cook_money>0)?true:false;
$rmbboxClsname = ($cook_money >= $money && $cook_money>0 )?' class="on"':' class="off"';?>
<style>
.my_pay{top:4.4rem;background-color:#fff;display:none}
.my_pay .table{width:90%;border-collapse:collapse;box-sizing:border-box;background-color:#fff;margin:0 auto 1.5rem auto}
.my_pay .table td{padding:1.3rem .8rem;border-bottom:#f8f8f8 1px solid}
.my_pay .table em{font-size:1.2rem;display:block}
.my_pay .table tr.on td{color:#000}
.my_pay .table tr.on td em{color:#f70;}
.my_pay .table tr.off td{color:#999}
.my_pay .table tr.off td em{color:#999;}
.my_pay .table tr.off td .ico{filter:gray;-webkit-filter:grayscale(1);filter:alpha(opacity=40);-moz-opacity:0.4;opacity:0.4}
.my_pay .checkskin-label i.i3{border-radius:3rem}
.my_pay .payinfo{text-align:left;padding:4.5rem 2rem 2rem;border-bottom:1px #f2f2f2 solid;font-size:1.6rem}
.my_pay .payinfo div:nth-child(1){float:left}
.my_pay .payinfo div:nth-child(2){float:right}
.checkskin-label:hover i{border-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.checkskin:checked + label.checkskin-label i {background-color:<?php echo $_ZEAI['mob_mbcolor'];?>;border-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
</style>
<?php if(is_mjapp()){?><script src="<?php echo HOST;?>/api/magapp/magjs-x.js?<?php echo $_ZEAI['cache_str'];?>"></script><?php }?>
<div id="czbox" class="my_pay">
    <div class="payinfo">
			<?php
			switch ($kind) {
				case 1:$orderid_title = utitle($maxg).'('.get_if2_title($maxif2).')VIP升级';break;
				case 2:$orderid_title = utitle($cook_grade).$_ZEAI['loveB'].'充值';break;
				case 3:$orderid_title = utitle($cook_grade).'余额充值';break;
				case 4:$orderid_title = utitle($cook_grade).'活动报名';break;
				case 7:$orderid_title = utitle($cook_grade).'诚信认证';break;
				case 8:$orderid_title = utitle($cook_grade).'文章赞赏';break;
				case 9:$orderid_title = utitle($cook_grade).'注销资料';break;
				case 13:$orderid_title = utitle($cook_grade).'互选相亲报名';break;
				case 19:$orderid_title = utitle($cook_grade).'置顶';break;
				case 20:$orderid_title = '新用户注册审核费';break;
				case 21:$orderid_title = '单身群入群费';break;
				case 22:$orderid_title = '情感测试费';break;
				case 23:$orderid_title = '单次牵线';break;
				case 24:$orderid_title = '脱单盲盒';break;
			}
			?>
            <div id="orderid_title"><?php echo $orderid_title;?></div>
            <div>金额：<font class="Cf60" id="money_str">￥<?php echo $money;?></font></div>
            <div class="clear"></div>
    </div>
    <table class="table">
    <?php if ($kind !=3 && $kind !=8 && $kind !=9 && $kind !=20 && $cook_money>0 && $_VIP['ifmoney'] == 1){?>
      <tr id="rmbbox"<?php echo $rmbboxClsname;?>>
        <td width="40" align="right"><i class="ico" style="color:#EE5A4E;font-size:3.6rem">&#xe61a;</i></td>
        <td align="left"><font class="S14">余额支付</font>
        	<?php if ($ifrmb){?>
        	<em id="money_tips">可用余额￥<?php echo str_replace(".00","",$cook_money);?>元</em>
            <?php }else{ ?>
            <em id="money_tips">当前￥<?php echo str_replace(".00","",$cook_money);?>，账户余额不足</em>
            <?php }?>
        </td>
        <td width="45" align="left">
            <input type="checkbox" id="rmbpay" name="rmbpay" class="checkskin payli"<?php echo (!$ifrmb)?' disabled':'';?>>
            <label for="rmbpay" class="checkskin-label"><i class="i3"></i></label>
        </td>
      </tr>
      <?php }?>
      <tr<?php echo (!$ifweixinpay)?' style="display:none;"':'';?>>
        <td width="40" align="right"><i class="ico" style="color:#45C01A;font-size:3.3rem">&#xe6b7;</i></td>
        <td align="left"><font class="S14">微信支付</font><em class="C999">通过微信零钱钱包支付</em></td>
        <td width="45" align="left">
            <input type="checkbox" id="wxpay" name="wxpay" class="checkskin payli" checked>
            <label for="wxpay" class="checkskin-label"><i class="i3"></i></label>
        </td>
      </tr>
	<?php if (!is_weixin()){?>
      <tr<?php echo (!$ifalipay)?' style="display:none;"':'';?>>
        <td width="40" align="right" style="padding-right:10px"><i class="ico" style="color:#02AAF0;font-size:3.3rem">&#xe656;</i></td>
        <td align="left"><font class="S14">支付宝支付</font><em class="C999">推荐有支付宝账户的用户使用</em></td>
        <td width="45" align="left">
            <input type="checkbox" id="alipay" name="alipay" class="checkskin payli">
            <label for="alipay" class="checkskin-label"><i class="i3"></i></label>
        </td>
      </tr>
	<?php }?>
    </table>
	<input type="hidden" name="paykind" id="paykind" value="">
    <button type="button" class="btn size4 zeaibg W90_ " id="btn">立即支付</button>
	<script>
    var kind   = <?php echo $kind;?>,
    money      = <?php echo $money;?>,
    cook_money = <?php echo floatval($cook_money);?>,
    jump_url   = '<?php echo $jump_url;?>';
    <?php if ($kind !=3 && $kind !=8 && $kind !=9 && $kind !=20 && $_VIP['ifmoney'] == 1){?>
    //RMB
    if (cook_money >= money && !zeai.empty(o('rmbpay'))){
        rmbpay.onclick = function(){
            paykind.value = 'rmbpay';
            payListener(this);
        }
    }
    <?php }?>
    //WX
    wxpay.onclick = function(){
        paykind.value = 'wxpay';
        payListener(this);
    }
    <?php if (!is_weixin()){?>
    //ZFB
    alipay.onclick = function(){
        paykind.value = 'alipay';
        payListener(this);
    }
    <?php }?>
    function payListener(curdom){
        var i=0;
        zeai.listEach('.payli',function(obj){
            if (curdom != obj)obj.checked = false;
            if (obj.checked == true)i++;
        });
        if (i>0){
            btn.removeClass('HUI');btn.addClass('LV2');
        }else{
            btn.removeClass('LV2');
            if (!btn.hasClass('HUI'));btn.addClass('HUI');
        }
    }
    //BTN
    btn.onclick = function(){
        var i=0;
        zeai.listEach('.payli',function(obj){if (obj.checked == true){
            i++;paykind.value = obj.name;
        }});
        if (i==0 || paykind.value!='rmbpay' && paykind.value!='wxpay' && paykind.value!='alipay'){
            zeai.msg('亲~ 请选择支付方式');
        }else{
			var data = {submitok:'ajax_pay_money_loveb',money:money,paykind:paykind.value,kind:kind,jump_url:jump_url};
			if(kind==1){
				Object.assign(data,{grade:grade.value,if2:if2.value});	
			}else if(kind==9){
				Object.assign(data,{content:content});	
			}else if(kind==19){
				Object.assign(data,{objid:o('objid').value});
			}else if(kind==23){
				Object.assign(data,{qx_uid:qx_uid.value,qx_admid:qx_admid.value});
			}else if(kind==24){
				Object.assign(data,{inout:inout.value});
			}
            var jsonurl={url:HOST+'/api/zeai_PAY'+zeai.extname,js:1,data:data};
			if(kind==20)jsonurl={url:HOST+'/api/zeai_PAY'+zeai.extname,js:0,data:data};
			//余额
            if (paykind.value=='rmbpay'){
                zeai.ajax(jsonurl,function(e){var rs=zeai.jsoneval(e);
                    zeai.msg(0);	
                    if (rs.flag==1){
						zeai.alert(rs.msg,rs.jump_url);
                    }else{
                        zeai.msg(rs.msg);	
                    }
                });
			//微信
            }else if(paykind.value=='wxpay'){
                zeai.msg('正在微信支付..');
                zeai.ajax(jsonurl,function(e){
					var rs=zeai.jsoneval(e);
                    zeai.msg(0);
                    if (rs.flag==1){
                        if (rs.trade_type=='H5'){
                            zeai.openurl(rs.redirect_url);
						}else if(rs.trade_type=='MAGAPP'){
							mag.pay(rs.jsApiParameters, function(){
								zeai.msg("支付成功");setTimeout(function(){zeai.openurl(rs.jump_url);},1500);
							},function(){
								zeai.msg("支付失败回调");
							});
                        }else{
                            function jsApiCall(){
                                WeixinJSBridge.invoke('getBrandWCPayRequest',rs.jsApiParameters,function(res){//WeixinJSBridge.log(res.err_msg);//alert(JSON.stringify(res));
                                    if(res.err_msg == "get_brand_wcpay_request:ok"){
                                        zeai.msg("支付成功");
										setTimeout(function(){zeai.openurl(rs.jump_url);},1000);
                                    }else{
                                       zeai.msg("支付失败,请返回重新支付");
                                    }				
                                });
                            }
                            if (typeof WeixinJSBridge == "undefined"){
                                if( document.addEventListener ){
                                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                                }else if (document.attachEvent){
                                    document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                                }
                            }else{
                                jsApiCall();
                            }
                        }
                    }else{
                        zeai.msg(rs.msg);	
                    }
                });
            <?php if (!is_weixin()){?>
            }else if(paykind.value=='alipay'){
                zeai.msg('正在支付宝支付..',{time:20});
                zeai.ajax(jsonurl,function(e){rs=zeai.jsoneval(e);
                    zeai.msg(0);	
                    if (rs.flag==1){
                        delete rs.flag;zeai.post(HOST+'/api/ali/pay/wappay/pay'+zeai.extname,rs);	
                    }else{
                        zeai.msg(rs.msg);	
                    }
                });
            <?php }?>
            }
        }
    }
    </script>
</div>